package com.wl.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wl.dao.DeptMapper;
import com.wl.entity.Dept;
import com.wl.service.DeptService;
import com.wl.util.PageData;

@Service
public class DeptServiceImpl implements DeptService {

	//注入DeptMapper对象
	@Autowired
	private DeptMapper dm;
	
	/**
	 * 根据部门编号查找部门信息
	 */
	@Override
	public Dept selectDeptById(int deptid) {
		// TODO Auto-generated method stub
		return dm.selectByPrimaryKey(deptid);
	}

	/**
	 * 模糊+分页查询
	 */
	@Override
	public PageData<Dept> selectDeptByLike(int page, int limit, String content) {
		// TODO Auto-generated method stub
		int start = (page - 1) * limit;
		List<Dept> data = dm.selectByPage(start, limit, content);
		int count = dm.selectCount(content);
		PageData<Dept> pd = new PageData<>(data, count, limit, page);
		return pd;
	}

	/**
	 * 增加部门的方法
	 */
	@Override
	public boolean addDept(Dept dept) {
		// TODO Auto-generated method stub
		boolean flag=dm.addDept(dept);
		return flag;
	}

	/**
	 * 删除的方法
	 */
	@Override
	public boolean delDeptById(int deptid) {
		// TODO Auto-generated method stub
		return dm.deleteByPrimaryKey(deptid)>0;
	}

	/**
	 * 修改部门信息
	 */
	@Override
	public boolean updateDept(Dept dept) {
		// TODO Auto-generated method stub
		return dm.updateByPrimaryKeySelective(dept)>0;
	}
	
	/**
	 * 查询所有
	 */
	@Override
	public List<Dept> selectAllDept() {
		// TODO Auto-generated method stub
		return dm.selectAllDept();
	}
	
	/**
	 * 根据部门名称查找部门信息
	 */
	@Override
	public Dept selectDeptByName(String deptname) {
		// TODO Auto-generated method stub
		return dm.selectDeptByName(deptname);
	}


	
	/**
	 * 根据部门名称查找02环节审批人
	 * @param deptname
	 * @return
	 */
	@Override
	public Dept selectByDeptName(String deptname) {
		// TODO Auto-generated method stub
		return dm.selectByDeptName(deptname);
	}
}
